cmake_minimum_required( VERSION 2.6 )
project("QPhoenix")

SET (CMAKE_BUILD_TYPE Debug)

ADD_DEFINITIONS(${QT_DEFINITIONS})
ADD_DEFINITIONS(-DQT_NETWORK)
ADD_DEFINITIONS(-DQT_XML)
ADD_DEFINITIONS(-DQT_DECLARATIVE)
#ADD_DEFINITIONS(-DQT_DBUS)

ADD_DEFINITIONS(-DUNICODE)

find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})


# Some compile options
IF(NOT MSVC)
    IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
        SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC ")
    ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
ENDIF()



# Uninstall target
configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"Вечером 24 июля в своей квартире был арестован администратор одного из крупнейших развлекательных порталов рунета Намазов Н.
    "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
    IMMEDIATE @ONLY)

add_custom_target(uninstall
    COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)





# Paths to resources
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD
OR ${CMAKE_SYSTEM_NAME} STREQUAL NetBSD)
    set (QGT_L10N_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/qphoenix/l10n)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qphoenix.desktop ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.desktop COPYONLY)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/artwork/icons/eyeworld_icon.png ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.png COPYONLY)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt COPYONLY)

    set( QGT_LICENSE_PATH {CMAKE_INSTALL_PREFIX}/share/qphoenix/LICENSE.txt)
    set( QGT_BINARY_PATH ${CMAKE_INSTALL_PREFIX}/bin/qphoenix)
    set( QGT_ICONS_PATH ${CMAKE_INSTALL_PREFIX}/share/qphoenix/icons)
    set( QGT_FLAGS_PATH ${CMAKE_INSTALL_PREFIX}/share/qphoenix/flags)
    set( QGT_APP_ICON ${CMAKE_INSTALL_PREFIX}/share/pixmaps/qphoenix.png)
    set( QGT_DESKTOP_PATH ${CMAKE_INSTALL_PREFIX}/share/applications/qphoenix.desktop)
endif(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD
OR ${CMAKE_SYSTEM_NAME} STREQUAL NetBSD)

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL Os2)
    set (QGT_L10N_DIRECTORY "..\l10n")
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qphoenix.desktop ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.desktop COPYONLY)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/artwork/icons/eyeworld_icon.png ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.png COPYONLY)
    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt COPYONLY)

    set( QGT_LICENSE_PATH {CMAKE_INSTALL_PREFIX}\\LICENSE.txt)
    set( QGT_BINARY_PATH ${CMAKE_INSTALL_PREFIX}\\qphoenix)
    set( QGT_ICONS_PATH ${CMAKE_INSTALL_PREFIX}\\icons)
    set( QGT_FLAGS_PATH ${CMAKE_INSTALL_PREFIX}\\flags)
    set( QGT_APP_ICON ${CMAKE_INSTALL_PREFIX}\\qphoenix.png)
endif(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL Os2)


# Necessary dirs
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_INCLUDE_PATH}
src
src/apiwrap
src/settings
src/widgets
src/tools
src/includes
src/dictionaries
src/translators
src/plugins
src/tts)

# 3rdp code
add_subdirectory(src/3rdparty/qxtshortcut)
add_subdirectory(src/3rdparty/qxtjson)

#Modules
#add_subdirectory(src/translators)
#add_subdirectory(src/dictionaries)
#add_subdirectory(src/tts)
#add_subdirectory(src/plugins)



# Wrapping file with paths
configure_file(src/includes/defines.h.in src/includes/platform.h)


# Source code
set(HEADERS

#Main

src/mainwindow.h
src/defines.h

# Tools

#src/tools/icons.h
src/tools/popup.h
#src/tools/languagesfactory.h
src/tools/texttools.h
src/tools/dbusadaptor.h


#Widgets
src/widgets/textfindwidget.h
src/widgets/shortcutwidget.h

#Settings
src/settings/appearanceconfig.h
src/settings/translationconfig.h
src/settings/pronounceconfig.h
src/settings/proxyconfig.h
src/settings/notificationsconfig.h
src/settings/exceptionsconfig.h
src/settings/historyconfig.h
src/settings/dictionaryconfig.h
#src/settings/languagesconfig.h
src/settings/shortcutconfig.h
src/settings/settings.h


#translators
src/translators/translatorsloader.h
src/translators/translator_interface.h


#common
src/common/moduleinfo.h

)

# Source code
set(SOURCES

#Main

src/mainwindow.cpp
#src/application.cpp
src/main.cpp

# Tools

src/tools/popup.cpp
#src/tools/languagesfactory.cpp
src/tools/texttools.cpp



#Widgets
src/widgets/textfindwidget.cpp
src/widgets/shortcutwidget.cpp

#Settings
src/settings/appearanceconfig.cpp
src/settings/translationconfig.cpp
src/settings/pronounceconfig.cpp
src/settings/proxyconfig.cpp
src/settings/notificationsconfig.cpp
src/settings/exceptionsconfig.cpp
src/settings/historyconfig.cpp
src/settings/dictionaryconfig.cpp
#src/settings/languagesconfig.cpp
src/settings/shortcutconfig.cpp

#Translators
src/translators/translatorsloader.cpp

)

set (FILES_TO_TRANSLATE ${SOURCES} ${HEADERS})



# Translations target
#file (GLOB TRANSLATIONS_FILES src/l10n/*.ts)
set (TRANSLATIONS_FILES
	src/l10n/English.ts
	src/l10n/Russian.ts
	src/l10n/Ukrainian.ts
	src/l10n/Japanese.ts
)

option (UPDATE_TRANSLATIONS "Update source translation src/l10n/*.ts files (WARNING: make clean will delete the source .ts files! Danger!)")
if (UPDATE_TRANSLATIONS)
  qt4_create_translation(QM_FILES ${FILES_TO_TRANSLATE} ${TRANSLATIONS_FILES})
else (UPDATE_TRANSLATIONS)
  qt4_add_translation(QM_FILES ${TRANSLATIONS_FILES})
endif (UPDATE_TRANSLATIONS)

add_custom_target (lupdate DEPENDS ${QM_FILES})


# Wrapping Source files
qt4_wrap_cpp(MOC_SOURCES ${HEADERS})


# Compiling primary executable
add_executable(qphoenix ${SOURCES}
	       ${MOC_SOURCES}  ${QM_FILES})
target_link_libraries(qphoenix ${QT_LIBRARIES} ${QT_QTNETWORK_LIBRARIES} ${QT_QTXML_LIBRARIES} qxtjson qxtshortcut)


# This hack necessary on fedora :)
if (Q_WS_X11)
    include_directories(${X11_Xlib_INCLUDE_PATH} )
    target_link_libraries(qphoenix ${X11_LIBRARIES})
endif (Q_WS_X11)


file ( GLOB ICONS ${CMAKE_CURRENT_SOURCE_DIR}/src/artwork/icons/*.png)
file ( GLOB FLAGS ${CMAKE_CURRENT_SOURCE_DIR}/src/artwork/flags/*.png)

# install for linux
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux OR ${CMAKE_SYSTEM_NAME} STREQUAL FreeBSD)


    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION ${QGT_LICENSE_PATH})
    install(TARGETS qphoenix DESTINATION ${QGT_BINARY_PATH})
    install( FILES ${ICONS} DESTINATION ${QGT_ICONS_PATH})
    install( FILES ${FLAGS} DESTINATION ${QGT_FLAGS_PATH})

    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.desktop  DESTINATION ${QGT_DESKTOP_PATH})
    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.png  DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps)
    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.png  DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/22x22/apps)
    install( FILES ${QM_FILES} DESTINATION ${QGT_L10N_DIRECTORY})
endif()


# install for windows
if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL Os2)

    #set( QGT_DESKTOP_PATH ${CMAKE_INSTALL_PREFIX}/share/applications/qgoogletranslator.desktop)

    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt DESTINATION ${QGT_LICENSE_PATH})
    install(TARGETS qphoenix DESTINATION ${QGT_BINARY_PATH})
    install( FILES ${ICONS} DESTINATION ${QGT_ICONS_PATH})
    install( FILES ${FLAGS} DESTINATION ${QGT_FLAGS_PATH})

    #install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qgoogletranslator.desktop  DESTINATION ${QGT_DESKTOP_PATH})
    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.png  DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps)
    install( FILES ${CMAKE_CURRENT_BINARY_DIR}/qphoenix.png  DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/22x22/apps)
    install( FILES ${QM_FILES} DESTINATION ${QGT_L10N_DIRECTORY})
endif()
